using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.PlayerLoop;

[Serializable]
public class InputBehavior : PlayableBehaviour
{
    public bool TimeLinePause;
    public PlayableDirector director;

    private bool readyToPause=false;
    private bool clipPlayed = false;

    public override void OnPlayableCreate(Playable playable)
    {
        director=playable.GetGraph().GetResolver() as PlayableDirector;
    }

    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        if (!clipPlayed && info.weight>0f)
        {
            if (Application.isPlaying)
            {
                if (TimeLinePause)
                {
                    readyToPause = true;
                }
            }

            clipPlayed = true;
        }
    }

    public override void OnBehaviourPause(Playable playable, FrameData info)
    {
        if (readyToPause)
        {
            readyToPause = false;
            GameManager.Instance.PauseGame(director);
        }

        clipPlayed = false;
    }
}
